package com.gaohe.help.controller;

import java.util.List;
import java.io.IOException;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.gaohe.common.log.annotation.Log;
import com.gaohe.common.log.enums.BusinessType;
import com.gaohe.common.security.annotation.RequiresPermissions;
import com.gaohe.help.domain.FmHelp;
import com.gaohe.help.service.IFmHelpService;
import com.gaohe.common.core.web.controller.BaseController;
import com.gaohe.common.core.web.domain.AjaxResult;
import com.gaohe.common.core.utils.poi.ExcelUtil;
import com.gaohe.common.core.web.page.TableDataInfo;

/**
 * 互助订单Controller
 * 
 * @author ruoyi
 * @date 2025-06-03
 */
@RestController
@RequestMapping("/help")
public class FmHelpController extends BaseController
{
    @Autowired
    private IFmHelpService fmHelpService;

    /**
     * 查询互助订单列表
     */
    @RequiresPermissions("help:help:list")
    @GetMapping("/list")
    public TableDataInfo list(FmHelp fmHelp)
    {
        startPage();
        List<FmHelp> list = fmHelpService.selectFmHelpList(fmHelp);
        return getDataTable(list);
    }

    /**
     * 导出互助订单列表
     */
    @RequiresPermissions("help:help:export")
    @Log(title = "互助订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FmHelp fmHelp)
    {
        List<FmHelp> list = fmHelpService.selectFmHelpList(fmHelp);
        ExcelUtil<FmHelp> util = new ExcelUtil<FmHelp>(FmHelp.class);
        util.exportExcel(response, list, "互助订单数据");
    }

    /**
     * 获取互助订单详细信息
     */
    @RequiresPermissions("help:help:query")
    @GetMapping(value = "/{helpId}")
    public AjaxResult getInfo(@PathVariable("helpId") Long helpId)
    {
        return success(fmHelpService.selectFmHelpByHelpId(helpId));
    }

    /**
     * 新增互助订单
     */
    @RequiresPermissions("help:help:add")
    @Log(title = "互助订单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FmHelp fmHelp)
    {
        return toAjax(fmHelpService.insertFmHelp(fmHelp));
    }

    /**
     * 修改互助订单
     */
    @RequiresPermissions("help:help:edit")
    @Log(title = "互助订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FmHelp fmHelp)
    {
        return toAjax(fmHelpService.updateFmHelp(fmHelp));
    }

    /**
     * 删除互助订单
     */
    @RequiresPermissions("help:help:remove")
    @Log(title = "互助订单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{helpIds}")
    public AjaxResult remove(@PathVariable Long[] helpIds)
    {
        return toAjax(fmHelpService.deleteFmHelpByHelpIds(helpIds));
    }
}
